package com.example.admin_oa.controller;

import cn.hutool.core.date.DateUtil;
import com.alibaba.excel.util.StringUtils;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.comment_oa.aspact.Permission;
import com.example.comment_oa.util.AccountListener;
import com.example.admin_oa.model.mapper.SysUserMapper;
import com.example.admin_oa.model.service.SysUserService;
import com.example.comment_oa.pojos.SysUser;
import com.example.comment_oa.response.AjaxResponse;
import com.example.comment_oa.util.EaxyUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("adminOa/user")
@CrossOrigin
public class UserController {
    @Resource
    SysUserMapper sysUserMapper;
    @Resource
    SysUserService sysUserService;

//    @RequiresPermissions("attendance")
    @PostMapping("/query")
    public AjaxResponse userQuery(@RequestBody SysUser sysUser){
        return AjaxResponse.success(sysUserMapper.SysUserEmp());
    }

    @PostMapping("/Dubbo")
    public AjaxResponse dd(){
        SysUser sysUser = sysUserService.newOne();
        return AjaxResponse.success();
    }

    @PostMapping("/selectByUserNo/{userNo}")
    public AjaxResponse selectByUser(@PathVariable("userNo")String userNo){
        return AjaxResponse.success(sysUserService.selectByUserNo(userNo));
    }

    @PostMapping("addUserRole")
    public AjaxResponse add(@RequestBody String [] list){
        return AjaxResponse.success(sysUserService.updateUserRole(list));
    }

    @Permission("system:user:export")
    @PostMapping("daoChu")
    public AjaxResponse daoChu(@RequestBody List<SysUser> sysUsers){
        if(sysUsers.isEmpty()){
            return AjaxResponse.success(1);
        }
        return AjaxResponse.success(EaxyUtils.write("用户列表"+ DateUtil.formatDate(new Date()),sysUsers));
    }

    @PostMapping("daoru")
    public AjaxResponse daoRu(@RequestBody JSONObject files){
        System.out.println(files.getString("fi"));
        EaxyUtils.read(files.getString("fi"),SysUser.class,sysUserMapper);
        return AjaxResponse.success();
    }
}
